﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using MU2DLIB.Graphic;
using MU2DLIB.Input;
using MU2DLIB.Settings;

namespace MU2DLIB.Engine
{
    public class Engine : Game
    {
        #region Declaration

        private const int MINRESOLUTIONWIDTH = 1024;

        private const int MINRESOLUTIONWIDTH = 768;

        private static GraphicsDeviceManager m_GraphicsDeviceManager = null;

        private static ContentManager m_ContentManager = null;

        private static String m_WindowTitle;

        private static int m_ResolutionWidth;

        private static int m_ResolutionHeight;

        private static bool m_IsFullscreen;

        private static bool m_IsActive;

        #endregion

        #region Constructor

        public Engine(String windowTitle)
        {
            m_GraphicsDeviceManager = new GraphicsDeviceManager(this);
            m_ContentManager = new ContentManager(this.Services);
            m_WindowTitle = windowTitle;
            m_IsActive = false;
        }

        #endregion

        #region Properties



        #endregion

        #region Methods

        public void ApplyGraphics()
        {
            if (m_GraphicsDeviceManager == null)
                return;

            this.Window.Title = m_WindowTitle;

            int resolutionWidth = Graphics.Default.ResolutionWidth;
            int resolutionHeight = Graphics.Default.ResolutionHeight;

            if (resolutionWidth <= 0 || resolutionHeight <= 0)
            {
                m_GraphicsDeviceManager.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
                m_GraphicsDeviceManager.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
            }

            m_GraphicsDeviceManager.PreferredBackBufferWidth = resolutionWidth;
            m_GraphicsDeviceManager.PreferredBackBufferHeight = resolutionHeight;
            m_GraphicsDeviceManager.IsFullScreen = Graphics.Default.IsFullscreen;

            m_GraphicsDeviceManager.ApplyChanges();
        }

        protected new virtual void Initialize()
        {
            base.Initialize();
        }

        #endregion
    }
}
